
#include "IA.h"

Ia::Ia(void)
{
};

Ia::~Ia(void)
{
};

void Ia::update(Plane *player, Plane* enemies, float seconds_elapsed)
{
	if(player->hitpoints>0)
	{
		pos = enemies->getPosition();
		front = enemies->model.frontVector();
		/*up = enemies->model.topVector();*/
		right = enemies->model.rightVector();

		target = player->getPosition();	
		T = (target - pos).normalize();

		angle = front.dot(T);
		dir = right.dot(T);

		if(dir < -0.02) dir = -1;
		else if(dir>0.02) dir= 1;
		else dir=0;
		distance = (target - pos).length();
	
		enemies->model.rotateLocal(dir*seconds_elapsed, Vector3(0,0,-1));
		enemies->model.rotateLocal(angle * seconds_elapsed,Vector3(1,0,0)); 

		if(distance>20.0) enemies->straight(enemies->model,player->speed/5);
		//else enemies->fire();
	}
	else return;
}



